#include "strategies/MaxMinDiscardStrategy.h"
#include "Query.h"

int MaxMinDiscardStrategy::pickDiscard (CCardStack* hand, bool lastCardPicked, const GameState* gameState) {
    int handRange = lastCardPicked ? 3 : 4;
    int otherPlayer = (gameState->getCurrPlayer() + 1) % 2;
    CCardStack oppHand = gameState->getCardsPickedUpAndHeldByPlayer(otherPlayer);
    int numUnknownCards = 3 - oppHand.Size();
    decisionCertainty = 100 / (numUnknownCards + 1);
    int toDiscard = 0;
    int bestDifference = hand->Value(0) - Query::maxGainFromCard(oppHand, CCard(hand->at(0).GetIndex()));
    for (int i = 1; i < handRange; i++) {
        int difference = hand->Value(i) - Query::maxGainFromCard(oppHand, CCard(hand->at(i).GetIndex()));
        if (difference > bestDifference) {
            bestDifference = difference;
            toDiscard = i;
        }
    }
    return toDiscard;
}
